package kr.co.skplanet.commute.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "member")
public class Member {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO) // ???�??.
	private long id;
	
	@Column(name = "email")
	@JsonIgnore
	private String email;
	@Column(name = "password")
	@JsonIgnore
	private String password;
	@Column(name = "auth_key")
	@JsonIgnore
	private String authKey;
	@Column(name = "salt")
	@JsonIgnore
	private String salt;
	
	@OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC")
	private List<Route> routes;
	
	public List<Route> getRoutes() {
		return routes;
	}

	public void setRoutes(List<Route> routes) {
		this.routes = routes;
	}

	public Member() {
		
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	public void addPoint(Route route) {
		if(routes == null) {
			routes = new ArrayList<Route>();
		}
		routes.add(route);
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAuthKey() {
		return authKey;
	}

	public void setAuthKey(String authKey) {
		this.authKey = authKey;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	@Override
	public String toString() {
		return "Member [id=" + id + ", email=" + email + ", password="
				+ password + ", points=" + /*points +*/ "]";
	}

}
